function [vl_lwin1,vh_lwin1,vl_llose1,vh_llose1,p_lwin1,p_llose1]=transition_prob_stage1(parameter,tpORtp3h,Cpm25,parameter_fixed,c_l,c_h,V_l,V_h,age_l,age_h)


N=size(c_l,1);

% Conditions on age for which delta_ageHet is added to delta (e.g., above p75 player age), and rho_ageHet is multiplied to contest prize 
ageHet_l = (age_l>27.2);
ageHet_h = (age_h>27.2);

% Parameters that are fixed
cutoff_tp=parameter_fixed(1);
cutoff_pm=parameter_fixed(2);
delta_0  =parameter_fixed(3);

% Parameters that are estimated
k       =parameter(1);
delta_tp=parameter(3);
delta_pm=parameter(4);
delta_tp_ageHet=parameter(5);
delta_pm_ageHet=parameter(6);

% Delta changes separately in the log of (1 +) the temperature or PM2.5 difference relative to a cutoff, i.e., temperature of 27 -> log (1 + 27 - cutoff) = log (1 + 27 - 27) = log 1 = 0; 28->.7 of delta; 43->2.8   
delta        = repmat(delta_0,N,1) + delta_tp        * log( max( (tpORtp3h - repmat(cutoff_tp,N,1)) , 0) + ones(N,1)) + delta_pm        * log( max( (Cpm25 - repmat(cutoff_pm,N,1)) , 0) + ones(N,1));
delta_ageHet =                       delta_tp_ageHet * log( max( (tpORtp3h - repmat(cutoff_tp,N,1)) , 0) + ones(N,1)) + delta_pm_ageHet * log( max( (Cpm25 - repmat(cutoff_pm,N,1)) , 0) + ones(N,1));

% Call on transition_prob_stage2: these are continuation values (in stage 2) conditional on stage-1 outcome
[vl_lwin2_lwon1,vh_lwin2_lwon1,vl_llose2_lwon1,vh_llose2_lwon1,vl_lwin2_llost1,vh_lwin2_llost1,vl_llose2_llost1,vh_llose2_llost1,p_lwin2_lwon1,p_llose2_lwon1,p_lwin2_llost1,p_llose2_llost1]=transition_prob_stage2(parameter,tpORtp3h,Cpm25,parameter_fixed,c_l,c_h,V_l,V_h,age_l,age_h);

% Conditional on lwon1
spread_l=vl_lwin2_lwon1-vl_llose2_lwon1;                    % Player l's stage-2 win/lose payoff spread, conditional on lwon1
spread_h=vh_llose2_lwon1-vh_lwin2_lwon1;                    % Player h's stage-2 win/lose payoff spread, conditional on lwon1
% Equilibrium effort costs incurred in stage 2: Different across players given different win/lose payoffs spreads in stage 2
effortcostl_stage2=k*spread_l.*( ((c_l./c_h).*(spread_h./spread_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(spread_h./spread_l)).^k).^2 );
effortcosth_stage2=k*spread_h.*( ((c_h./c_l).*(spread_l./spread_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(spread_l./spread_h)).^k).^2 );
    % CORNER: If vh_llose2_lwon1<=0 <=> spread_h<=0, then battle-1 loser (player h in this case) throws the towel in battle 2: it is best to not exert effort, finish 2-0 and secure CV=0, than to try to transition to 1-1 with CV<0
    effortcostl_stage2=effortcostl_stage2.*(vh_llose2_lwon1>0);
    effortcosth_stage2=effortcosth_stage2.*(vh_llose2_lwon1>0);
    zero_spread_h=(spread_h==0);                 % Need to handle division by spread_h=0, which returned NaN
    effortcosth_stage2(zero_spread_h)=0;

% lwin1
vl_lwin1=p_lwin2_lwon1.*vl_lwin2_lwon1 + p_llose2_lwon1.*vl_llose2_lwon1 - effortcostl_stage2 - delta - delta_ageHet.*ageHet_l;   % Continuation values (in stage 2) conditional on stage-1 outcome lwin1
vh_lwin1=p_lwin2_lwon1.*vh_lwin2_lwon1 + p_llose2_lwon1.*vh_llose2_lwon1 - effortcosth_stage2 - delta - delta_ageHet.*ageHet_h;
clear spread_l spread_h effortcostl_stage2 effortcosth_stage2 zero_spread_h;

% Conditional on llost1
spread_l=vl_lwin2_llost1-vl_llose2_llost1;                  % Player l's stage-2 win/lose payoff spread, conditional on llost1
spread_h=vh_llose2_llost1-vh_lwin2_llost1;                  % Player h's stage-2 win/lose payoff spread, conditional on llost1
% Equilibrium effort costs incurred in stage 2: Different across players given different win/lose payoffs spreads in stage 2
effortcostl_stage2=k*spread_l.*( ((c_l./c_h).*(spread_h./spread_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(spread_h./spread_l)).^k).^2 );
effortcosth_stage2=k*spread_h.*( ((c_h./c_l).*(spread_l./spread_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(spread_l./spread_h)).^k).^2 );
    % CORNER: If vl_lwin2_llost1<=0 <=> spread_l<=0, then battle-1 loser (player l in this case) throws the towel in battle 2: it is best to not exert effort, finish 0-2 and secure CV=0, than to try to transition to 1-1 with CV<0
    effortcostl_stage2=effortcostl_stage2.*(vl_lwin2_llost1>0);
    effortcosth_stage2=effortcosth_stage2.*(vl_lwin2_llost1>0);
    zero_spread_l=(spread_l==0);                 % Need to handle division by spread_l=0, which returned NaN 
    effortcostl_stage2(zero_spread_l)=0;

% llose1
vl_llose1=p_lwin2_llost1.*vl_lwin2_llost1 + p_llose2_llost1.*vl_llose2_llost1 - effortcostl_stage2 - delta - delta_ageHet.*ageHet_l; % Again, continuation values (in stage 2) conditional on stage-1 outcome llose1
vh_llose1=p_lwin2_llost1.*vh_lwin2_llost1 + p_llose2_llost1.*vh_llose2_llost1 - effortcosth_stage2 - delta - delta_ageHet.*ageHet_h;
clear spread_l spread_h effortcostl_stage2 effortcosth_stage2 zero_spread_l;

spread_l=vl_lwin1 -vl_llose1;                          % Player l's stage-1 win/lose payoff spread
spread_h=vh_llose1-vh_lwin1;                           % Player h's stage-1 win/lose payoff spread
% Equilibrium effort costs incurred in stage 1: Equal across symmetric players given equal win/lose payoff spreads in stage 1
effortcostl_stage1=k*spread_l.*( ((c_l./c_h).*(spread_h./spread_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(spread_h./spread_l)).^k).^2 );
effortcosth_stage1=k*spread_h.*( ((c_h./c_l).*(spread_l./spread_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(spread_l./spread_h)).^k).^2 );
    % CORNER: If spread_h<=0, then player h throws the towel already in battle 1: it is best not to exert effort already in battle 1, since CV at 1-0 is less negative than the CV at 0-1
    effortcostl_stage1=effortcostl_stage1.*(spread_h>0);
    effortcosth_stage1=effortcosth_stage1.*(spread_h>0);
    zero_spread_h=(spread_h==0);                 % Need to handle division by spread_h=0, which returned NaN
    effortcosth_stage1(zero_spread_h)=0;
% Divide a player's equilibrium effort cost by marginal cost to obtain effort choice; lambda=1
xl1=effortcostl_stage1./c_l;
xh1=effortcosth_stage1./c_h;
% Transition probabilities   
p_lwin1 = xl1.^k ./ (xl1.^k + xh1.^k);
    % CORNER
    p_lwin1(xl1==0)=1;              % In battle 1, player l exerts infinitesimally positive effort and wins over player h who exerts 0 effort
p_llose1=ones(N,1)-p_lwin1;
clear spread_l spread_h effortcostl_stage1 effortcosth_stage1 zero_spread_h;

end